<?php
/**
* 支付模块Api Controller
*
* 支付模块Api Controller的注意及说明
* 以下use模块请不要互相伤害
*
* @author    xiecz <xiecz@yunys.com.cn>
* @copyright 2016 QuanZhouYunYiShang Inc.
*/
namespace App\Http\Controllers\Api\Pay;
use App\Http\Controllers\Controller;
use Request, Response;
use App\Services\Pay\PayApi;
use App\Services\Tool\Pay\AlipayTool;

class PayController extends Controller {
	function __construct(PayApi $payApi,AlipayTool $alipayTool){
		$this->payApi		= $payApi;
		$this->alipayTool   = $alipayTool;
		$this->middleware('transaction',['only'=>['couponPay']]);
	}

	//支付宝
	function alipay(){
		$input	= Request::all();
		$result = $this->payApi->alipay($input);
		return response()->json($result);
	}

	function alipay_web(){
		$input  = Request::all();
		$order  = $this->payApi->alipay_web($input);
		if($order['state'] != 'M00000'){
			return $order['message'];
		}
		$data['out_trade_no'] = $order['result']['out_trade_no'];
		$data['total_fee']    = '0.01';$order['result']['total_fee'];
		$data['subject']      = $order['result']['subject'];
		$data['body']         = $order['result']['body'];
		// 跳转到支付页面。
		return redirect()->to($this->alipayTool->getPayLink($data));
	}

	//微信
	function wxPay(){
		$input	= Request::all();
		$result	= $this->payApi->wxPay($input);
		return response()->json($result);
	}
	//优惠券
	function couponPay(){
		$input	= Request::all();
		$result	= $this->payApi->couponPay($input);
		return response()->json($result);
	}

	//支付宝异步回调
	function alipayNotify(){
		$input	= Request::all();
		$result = $this->payApi->AlipayNotify($input);
		return $result;
	}
	//微信异步回调
	function weixinNotify(){
		$input  = Request::all();
		$result = $this->payApi->weixinNotify($input);
		return $result;
	}
	//代付回调
	function transferAccountsNotify(){
		$input  = Request::all();
		$result = $this->payApi->transfer_accounts_notify($input);
		return $result;
	}

	//支付宝退款回调
	function alirefund_notify(){
		$input	= Request::all();
		$result	= $this->payApi->alirefund_notify($input);
		return $result;
	}

	function getTest(){
		$input  = Request::all();
		$result = $this->payApi->test($input);
		return response()->json($result);
	}
}
